package org.vidi.jms.transaction;

import org.vidi.jms.common.ConnectionUtils;
import org.vidi.jms.common.Constants;

import javax.jms.*;

/**
 * @author vidi
 */
public class Producer {
    public static void main(String[] args) {
        try {
            QueueConnection connection = ConnectionUtils.getConnection();
            connection.start();
            // turn on transaction.
            QueueSession session = connection.createQueueSession(true, Session.DUPS_OK_ACKNOWLEDGE);
            Queue queue = session.createQueue(Constants.BASE_JMS_QUEUE_NAME);
            QueueSender sender = session.createSender(queue);
            TextMessage message = session.createTextMessage();
            message.setText("Hello, world!");
            sender.send(message);
            session.commit();
            session.close();
            connection.close();
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}
